package com.wangsd.web.coupon.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.wangsd.common.basicbean.Result;
import com.wangsd.common.exception.BusinessException;
import com.wangsd.common.utils.DateUtils;
import com.wangsd.web.MyController;
import com.wangsd.web.coupon.entity.*;
import com.wangsd.web.coupon.service.*;
import com.wangsd.web.coupon.vo.WxPay;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.wangsd.common.enums.ResultCode.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-09-10
 */
@Api(value = "wxActivityProduct", tags = "活动列表查询")
@RestController
@RequestMapping("/coupon/wxActivityProduct")
@Slf4j
public class WxActivityProductController extends MyController {

    @Autowired
    CompanyService companyService;

    @Autowired
    ActivityProductService activityProductService;

    @Autowired
    NewGiftService newGiftService;

    @ApiOperation(value = "查询显示抢购商品列表", notes = "查询显示抢购商品列表", httpMethod = "POST")
    @PostMapping("/selectActivityProduct")
    public Result selectActivityProduct() {
        Company company = companyService.selectByMiniAppid(getMiniAppid());
        try {
            ActivityProduct list = activityProductService.selectListByCompanyId(company.getId());
            return Result.success(list);
        } catch (Exception e) {
            log.error("selectActivityProduct", e);
        }
        return Result.fail("查询失败");
    }

    @ApiOperation(value = "查询新人礼", notes = "查询新人礼", httpMethod = "POST")
    @PostMapping("/selectNewGift/{pageNum}/{pageSize}")
    public Result selectNewGift(@PathVariable Integer pageNum,
                                @PathVariable Integer pageSize) {
        Company company = companyService.selectByMiniAppid(getMiniAppid());
        try {
            IPage<NewGift> list = newGiftService.selectListByCompanyId(pageNum, pageSize,company.getId());
            return Result.success(list);
        } catch (Exception e) {
            log.error("selectNewGift", e);
        }
        return Result.fail("查询失败");
    }
}